package xyz.lwm.lazycat.utility.resource;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;

/**
 * @author lwm
 */
public interface Resource {

    // get name of resource
    @NotNull String getName();

    // get path of resource
    @NotNull String getPath();

    // get new resource by child name
    @NotNull Resource get(String childName);

    // true if exists
    boolean exists();

    // true if it's file
    boolean isFile();

    // true if it's directory
    boolean isDir();

    // get input stream, close by user self
    InputStream getInputStream() throws IOException;

    // get classpath if it's classpath resource
    @Nullable String getClasspath();

    /**
     * 创建 file resource
     *
     * @param file file
     * @param classpath classpath
     * @return resource
     */
    static Resource createResource(File file, String classpath) {
        return new FileResource(file, classpath);
    }

    /**
     * 创建 jar resource
     *
     * @param name entry name
     * @param jarFile jar file
     * @return resource
     */
    static Resource createResource(String name, JarFile jarFile) {
        return new JarResource(name, jarFile);
    }

}